/***************************************************************************
 *   KShootout - online shootout card game.                                *
 *   Copyright (C) 2008, 2009  MacJariel                                   *
 *                                                                         *
 *   KShootout is free software: you can redistribute it and/or modify     *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   KShootout is distributed in the hope that it will be useful,          *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with KShootout.  If not, see <http://www.gnu.org/licenses/>.    *
 ***************************************************************************/
#ifndef __STRINGCONVERTER_H__
#define __STRINGCONVERTER_H__

#include "gametypes.h"

class QDateTime;
class QLocale;


////////////////////////////////////////////////////////////////////////////////
//    QString conversions
////////////////////////////////////////////////////////////////////////////////

inline QString toString(const QString& s)
{
    return s;
}

inline void fromString(const QString& s, QString& t)
{
    t = s.toInt();
}

////////////////////////////////////////////////////////////////////////////////
//    Integer conversions
////////////////////////////////////////////////////////////////////////////////


inline QString toString(const bool& b)
{
    return (b ? "true" : "false");
}

inline void fromString(const QString& s, bool& b)
{
    b = (s.toLower() == "true");
}

inline QString toString(const qint8& i)
{
    return QString::number(i);
}

inline void fromString(const QString& s, qint8& i)
{
    i = (qint8)s.toShort();
}

inline QString toString(const quint8& i)
{
    return QString::number(i);
}

inline void fromString(const QString& s, quint8& i)
{
    i = (quint8)s.toUShort();
}

inline QString toString(const qint16& i)
{
    return QString::number(i);
}

inline void fromString(const QString& s, qint16& i)
{
    i = s.toShort();
}

inline QString toString(const quint16& i)
{
    return QString::number(i);
}

inline void fromString(const QString& s, quint16& i)
{
    i = s.toUShort();
}

inline QString toString(const int& i)
{
    return QString::number(i);
}

inline void fromString(const QString& s, int& i)
{
    i = s.toInt();
}

inline QString toString(const uint& i)
{
    return QString::number(i);
}

inline void fromString(const QString& s, uint& i)
{
    i = s.toUInt();
}

inline QString toString(const long& i)
{
    return QString::number(i);
}

inline void fromString(const QString& s, long& i)
{
    i = s.toLong();
}

inline QString toString(const ulong& i)
{
    return QString::number(i);
}

inline void fromString(const QString& s, ulong& i)
{
    i = s.toULong();
}

inline QString toString(const qlonglong& i)
{
    return QString::number(i);
}

inline void fromString(const QString& s, qlonglong& i)
{
    i = s.toLongLong();
}

inline QString toString(const qulonglong& i)
{
    return QString::number(i);
}

inline void fromString(const QString& s, qulonglong& i)
{
    i = s.toULongLong();
}

////////////////////////////////////////////////////////////////////////////////
//    Enum conversions
////////////////////////////////////////////////////////////////////////////////

inline QString toString(const PlayerRole& r)
{
    return playerRoleToString(r);
}

inline void fromString(const QString& s, PlayerRole& r)
{
    r = stringToPlayerRole(s);
}

inline QString toString(const ClientType& r)
{
    return clientTypeToString(r);
}

inline void fromString(const QString& s, ClientType& r)
{
    r = stringToClientType(s);
}

inline QString toString(const PocketType& r)
{
    return pocketTypeToString(r);
}

inline void fromString(const QString& s, PocketType& r)
{
    r = stringToPocketType(s);
}

inline QString toString(const CardType& r)
{
    return cardTypeToString(r);
}

inline void fromString(const QString& s, CardType& r)
{
    r = stringToCardType(s);
}

inline QString toString(const ReactionType& r)
{
    return reactionTypeToString(r);
}

inline void fromString(const QString& s, ReactionType& r)
{
    r = stringToReactionType(s);
}

inline QString toString(const GameParticipantType& r)
{
    return gameParticipantTypeToString(r);
}

inline void fromString(const QString& s, GameParticipantType& r)
{
    r = stringToGameParticipantType(s);
}

inline QString toString(const CardSuit& r)
{
    return cardSuitToString(r);
}

inline void fromString(const QString& s, CardSuit& r)
{
    r = stringToCardSuit(s);
}

inline QString toString(const CardRank& r)
{
    return cardRankToString(r);
}

inline void fromString(const QString& s, CardRank& r)
{
    r = stringToCardRank(s);
}

inline QString toString(const GameState& r)
{
    return gameStateToString(r);
}

inline void fromString(const QString& s, GameState& r)
{
    r = stringToGameState(s);
}

inline QString toString(const GamePlayState& r)
{
    return gamePlayStateToString(r);
}

inline void fromString(const QString& s, GamePlayState& r)
{
    r = stringToGamePlayState(s);
}

////////////////////////////////////////////////////////////////////////////////
//    Qt Conversions
////////////////////////////////////////////////////////////////////////////////

QString toString(const QDateTime& r);

void fromString(const QString& s, QDateTime& r);

QString toString(const QList<QLocale>& r);

void fromString(const QString& s, QList<QLocale>& r);

#endif // __STRINGCONVERTER_H__
